/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>交易订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="ordersQuery" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="ordersQuery.ordersId" placeholder="输入订单号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker size="small" type="date" v-model="ordersQuery.createTimeMin" value-format="yyyy-MM-dd HH:mm:ss" placeholder="输入下单开始时间"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-date-picker size="small" type="date" v-model="ordersQuery.createTimeMax" value-format="yyyy-MM-dd HH:mm:ss" placeholder="输入下单结束时间"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-card class="box-card" style="margin-top: 10px">
    <el-table size="small" :data="tableData.slice((pageNum - 1) * pageSize, pageNum * pageSize)" border highlight-current-row v-loading="loading"
               element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
      <el-table-column sortable prop="ordersId" label="订单号"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="customerName" label="客户姓名"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="doctorName" label="医生姓名"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="category" label="订单类别"  show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.state ==0">植物</span>
          <span v-if="scope.row.state ==1">动物</span>
        </template>
      </el-table-column>
      <el-table-column sortable prop="startTime" label="症状开始时间"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="description" label="症状描述"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="state" label="订单状态"  show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.state ==0">未支付</span>
          <span v-if="scope.row.state ==1">已支付</span>
          <span v-if="scope.row.state ==2">未支付超时</span>
        </template>
      </el-table-column>
      <el-table-column sortable prop="payAmount" label="交易金额"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="createTime" label="下单时间"  show-overflow-tooltip>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">查看详细订单</el-button>
          <el-button size="mini" type="danger" @click="deleteUser(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click="closeDialog('editForm')">
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单状态">
              <el-select size="small" v-model="editForm.state" >
                <el-option label="未支付"  value="0"></el-option>
                <el-option label="已支付" value="1"></el-option>
                <el-option label="超时未支付" value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="订单号">
              <el-input size="small" v-model="editForm.ordersId" auto-complete="off"  disabled></el-input>
            </el-form-item>
            <el-form-item label="交易金额">
              <el-input size="small" v-model="editForm.payAmount" auto-complete="off"  disabled></el-input>
            </el-form-item>
            <el-form-item label="症状描述">
              <el-input size="small" v-model="editForm.description" auto-complete="off"  disabled></el-input>
            </el-form-item>
            <el-form-item label="症状图片">
              <el-input size="small" v-model="editForm.img" auto-complete="off"  disabled></el-input>
            </el-form-item>
            <el-form-item label="类别">
              <el-select size="small" v-model="editForm.category" >
                <el-option label="植物" value="0"></el-option>
                <el-option label="动物" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="症状开始时间">
              <el-input size="small" v-model="editForm.startTime" auto-complete="off"  disabled></el-input>
            </el-form-item>
            <el-form-item label="下单时间">
              <el-input size="small" v-model="editForm.createTime" auto-complete="off"  disabled></el-input>
            </el-form-item>
            <el-form-item label="客户姓名">
              <el-input size="small" v-model="editForm.customerName" auto-complete="off"  disabled></el-input>
            </el-form-item>

            <el-form-item label="医生姓名">
              <el-input size="small" v-model="editForm.doctorName" auto-complete="off"  disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!--分页-->
    <el-pagination
      :current-page="pageNum"
      :page-sizes="[2, 3, 4, 5,10, tableData.length]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.length"
    >
    </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { OrderList, OrderRefund, OrderDelete } from '../../api/payMG'
import axios from 'axios'
import Pagination from '../../components/Pagination'
import {getCookie} from "../../utils/util";
import {getInfo} from "../../api/userMG";
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 2,
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',
      tableData:[],
      editForm: {
        ordersId: '',
        state: '',
        description: '',
        img: '',
        category: '',
        startTime: '',
        createTime: '',
        customerName: '',
        doctorName: '',

      },
      ordersQuery: {},
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 创建完毕
   */
  created() {
    this.search()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 搜索事件
    search() {

      getInfo().then(res=> {
        console.log(res.data.data.Doctor)
        this.user = res.data.data.Doctor;
      })
      console.log(this.ordersQuery)
      OrderList(this.user.doctorId,this.ordersQuery).then(res => {
          this.loading = false
        this.listData = res.data.list
          console.log(this.listData)
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    //显示编辑界面
    handleEdit(row) {
      this.editFormVisible = true
      this.editForm = {...row };
    },
    // 删除公司
    deleteUser(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          OrderDelete(row.pkId)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '订单已删除!'
                })
                this.search()
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('订单信息删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>




